import {IResource, Resource} from './Resource';

class ResourceProxy implements IResource{
  logger:Logger = new Logger();
  resource:Resource = new Resource();
  fetch(userId:number):string{
    if(userId < 100){
      this.logger.log(`用户权限非法，id：${userId}`, 0);
      return null;
    }
    this.logger.log(`合法用户，可获取权限，id：${userId}`, 1);
    return this.resource.fetch(userId);
  }
}

class Logger{
  colors:Array<string> = ['red', 'blue'];
  log(message:string, level:number):void{
    let color:string = this.colors[level];
    console.log(`%c${message}`, `color:${color}`);
  }
}

export {ResourceProxy};